package com.senpai.ikhtiar;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	TextView txtView;
	Button btnPresident;
	Button btnParlemant;
	private static long back_pressed;
	AlertDialog.Builder builder;

	private ActionBar actionBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		actionBar = getActionBar();
		actionBar.setDisplayShowTitleEnabled(true);
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

		builder = new AlertDialog.Builder(this);
		builder.setMessage("Ikhtiar presidentielles sera actif le 4 novembre 2014");

		btnPresident = (Button) findViewById(R.id.btnPresident);
		btnPresident.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				AlertDialog dialog = builder.create();
				dialog.show();
			}
		});

		btnParlemant = (Button) findViewById(R.id.btnParlemenant);
		btnParlemant.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this,
						QuestionActivity.class);
				startActivity(intent);
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.activity_main_actions, menu);

		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case R.id.action_about:
			
			return true;
		case R.id.action_share:
			Share();
			return true;

		case R.id.action_rate:
			Rate();
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	public void onBackPressed() {
		if (back_pressed + 2000 > System.currentTimeMillis())
			super.onBackPressed();
		else
			Toast.makeText(getBaseContext(),
					"Appuyez de nouveau pour quitter!", Toast.LENGTH_SHORT)
					.show();
		back_pressed = System.currentTimeMillis();
	}

	private void Share() {
		Intent sendIntent = new Intent();
		sendIntent.setAction(Intent.ACTION_SEND);
		sendIntent.putExtra(Intent.EXTRA_TEXT, "https://github.com/sitepoint-examples/android-action-bar");
		sendIntent.setType("text/plain");
		startActivity(sendIntent);
	}
	
	private void Rate()
	{
		Uri marketUri = Uri.parse("market://details?id=com.mobifire.narutoshippudenepisodesfull");
		Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
		startActivity(marketIntent);
	}
}
